;; predicate.scm - (c) rohan drape, 2005

;; Predicate generators.

(define (=?? a) (lambda (b) (= a b)))
(define (eq?? a) (lambda (b) (eq? a b)))
(define (eqv?? a) (lambda (b) (eqv? a b)))
(define (equal?? a) (lambda (b) (equal? a b)))
(define (string=?? a) (lambda (b) (string= a b)))

;; Predicate composition.

(define-syntax compose?
  (syntax-rules ()
    ((_ rule predicate ...)
     (lambda (value) (rule (predicate value) ...)))))

(define-syntax and?
  (syntax-rules ()
    ((_ predicate ...) (compose? and predicate ...))))

(define-syntax or?
  (syntax-rules ()
    ((_ predicate ...) (compose? or predicate ...))))

;; f is a single argument procedure, the result is a function that
;; applies f to values that satisy the predicate p and is the identity
;; function for all other values.  The name is courtesy Ralf Lammel
;; and Simon Peyton Jones (in Haskell p argument is, of course,
;; elided).

(define (mkT f p?)
  (lambda (v) (if (p? v) (f v) v)))
